<?php
namespace Huodong\Controller;
use Library\Task\DbTask;
use Library\Wx;
use Library\SMS;
use Think\Crypt\Driver\Think;

/**
 * ／代码测试类
 *
 * @author pufan
 */
if (APP_DEBUG) {
    
class TestController {

    public function test_rand_by_weight() {
        header("Content-Type: text/html;charset=utf-8");
        set_time_limit(0);//0表示不限时
        error_reporting(E_ALL);
        ini_set( 'display_errors', 'On' );

        $shake = new \Library\Shake(2);
        $shake->test_rand_by_100weight_group();
    }
    
    public function test_wx() {
        $_SESSION['open_id'] = 'o9Vj9vno48jVaNUSLDiIYhR8elGM';
        $open_id = 'o9Vj9vno48jVaNUSLDiIYhR8elGM';
        $result = Wx::getUserInfo($open_id);
        var_dump($result);

        $mark = 'kaifa';
        $result = Wx::updateUserRemark($open_id, $mark);
        var_dump($result);
    }

    /*
     * 测试全局 原子加和原子减
     */
    public function test_thikphp_cache(){
        S('guowei_test', 1, 600);
        redisIncr('guowei_test');
        redisIncr('guowei_test');
        redisIncr('guowei_test');

        redisDecr('guowei_test');
        redisDecr('guowei_test');
        dump(' 2 is ok');
        echo 'result:'. S('guowei_test');
    }

    public function SwitchingBeacon(){
        $wxevent = new \Library\WxEvent();
        /*
         * guowei
         */
        $event = '{"ToUserName":"gh_e52449c80414","FromUserName":"o9Vj9vno48jVaNUSLDiIYhR8elGM","CreateTime":"1465813343","MsgType":"event","Event":"ShakearoundUserShake","ChosenBeacon":{"Uuid":"FDA50693-A4E2-4FB1-AFCF-C6EB07647825","Major":"10060","Minor":"15179","Distance":"4.3305555145975712","Rssi":"-68","MeasurePower":"-68"},"ChosenPageId":"3133581"}';
        $wxevent->handle_shakearoundusershake($event);
    }

/*    public function testMysqlEvent(){
        set_time_limit(0);
        $order = D('prizes_order');
        $curTime = time();
        $curTime= $curTime + 120;

        echo date('y-m-d H:i:s', $curTime);
        echo '<br>';
        for($loopNum = 600; $loopNum > 0; $loopNum--) {
            $curTime++;
            for($i=0; $i < 1000; $i++) {
                $eventTime = date('y-m-d H:i:s', $curTime);
                $sql = 'CREATE DEFINER=`bbt`@`%` EVENT `TestEvent'.$curTime.$i.'` ON SCHEDULE AT "'.$eventTime.'" ON COMPLETION NOT PRESERVE ENABLE DO UPDATE   `yy_user_prizes_count` SET `cur_day_num` = 0   WHERE  `update_time`  < curdate()';
                $result = $order->execute($sql);

            }
        }
        echo $eventTime;
        echo '<br>';
    }*/

    public function testMysqlEvent(){
        set_time_limit(0);
        $order = D('prizes_order');
        $curTime = time();
        $curTime= $curTime + 3600;

        $eventTime = date('y-m-d H:i:s', $curTime);

        $taskid = 'test'.$curTime;
        $data = 'UPDATE  `yy_user_prizes_count` SET `cur_day_num` = 0   WHERE  `update_time`  < curdate()';
        $sche = new DbTask();
        $sche->add($taskid, $data, $eventTime);


       /* $curTime = $curTime - 1800;
        $eventTime = date('y-m-d H:i:s', $curTime);
        $sche->updateTime($taskid, $eventTime);

        echo $eventTime;
        $sche->del($taskid);*/
        echo '<br>';
    }
    public function test_sms() {
        $sms = new SMS();
        $data['content'] = '《大话西游3》电影票1张';
        $data['code'] = '1111222';
        $phone = '15110162900';
        $result = $sms->sendMsg('SMS_14360190', $phone, $data);

        unset($data);
        $phone = '15110162900';
        $data['content'] = '抱抱堂爆米花1杯';
        $result = $sms->sendMsg('SMS_14295217', $phone, $data, '抱抱堂');
    }
}
}

